package com.erp.serviceImpl.baseDataServiceImpl;

import com.erp.dao.SupplierMapper;
import com.erp.pojo.Supplier;
import com.erp.pojo.SupplierExample;
import com.erp.service.baseDataService.ISupplierService;
import com.erp.utils.Msg;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by JayC
 * Date:2019/1/15
 * Time:19:45
 */
@Service
public class SupplierServiceImpl implements ISupplierService {

    @Autowired
    private SupplierMapper supplierMapper;

    Msg msg = new Msg();
    @Override
    public Msg getSupp(String type, int page, int limit) {

        SupplierExample example= new SupplierExample();
        SupplierExample.Criteria criteria = example.createCriteria();
        criteria.andTypeEqualTo(type);

        PageHelper.startPage(page,limit);

        List<Supplier> list = supplierMapper.selectByExample(example);

        PageInfo<Supplier> pagelist = new PageInfo<>(list);

        msg.setCode(0);
        msg.setCount(pagelist.getTotal());
        msg.setMsg("");
        msg.setData(pagelist.getList());

        System.out.println(msg);

        return msg;

    }

    @Override
    public void insertSup(Supplier supplier){
        supplierMapper.insertSelective(supplier);
    }

    @Override
    public void deleteSup(Long id) {
        supplierMapper.deleteByPrimaryKey(id);
    }


}
